package dahuiji.common.core;

import java.text.DateFormat;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间处理
 * 
 * @author Administrator
 * 
 */
public class DateCaozuo {
	public DateCaozuo() {

	}

	/**
	 * 在给定的时间上加日期
	 * 
	 * @param d
	 * @param w
	 * @return
	 * @throws ParseException
	 */
	public Date addTown(Date d, int w) throws ParseException {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(d);
		cal.add(Calendar.DATE, w);
		String addT = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
		return df.parse(addT);
	}

	/**
	 * 字符转date
	 * 
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public Date toDate(String date) throws ParseException {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.parse(date);

	}

	/**
	 * 
	 * @param date
	 * @return
	 */
	public String dateToString(Date date) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(date);
	}

	public String getNowDateString() {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String sD = df.format(date);
		return sD;
	}

	public String getNowDateStringHH() {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date date = new Date();
		String sD = df.format(date);
		return sD;
	}

	public Date getNowDate() {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date date = new Date();
		String sD = df.format(date);
		try {
			return df.parse(sD);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return null;
		}
	}

	/**
	 * 只得到日期，到那天
	 * 
	 * @return
	 */
	public Date getNowDateNotHH() {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date date = new Date();
		String sD = df.format(date);
		try {
			return df.parse(sD);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			return null;
		}
	}

}
